{% extends 'wiki/base.html' %}

{% set page_title = _('History for %(page_name)s', page_name=revision.title) %}
{% set feed_link = url_for('wiki/changes-atom', page_path=page_path) %}

{% block title %}{{ page_title }} - {{ sitename }}{% endblock %}

{%- block extrahead -%}
    {{- super() -}}
    <link type="application/atom+xml" rel="alternate" href="{{ feed_link }}" title="{{ _('Atom feed for this page') }}">
{% endblock %}

{% block content %}
    <h1>
        {{ page_title }}
        <ul class="actions">
            <li><span class="icon icon-feed"></span> <a href="{{ feed_link }}" title="{{ _('Atom feed for this page') }}">{{ _('Feed') }}</a></li>
        </ul>
    </h1>
    {% if revisions %}
        <p>{{ _('Here are the previous revisions for this page. To revert to an old revision, just access the selected one, edit and save it.') }}</p>
        <form method="post" action="{{ request.url }}" class="tipfy-form">
            <table class="grid" id="wiki-changes">
                <tbody>
                {% set row_class = cycler('odd', 'even') %}
                {% for revision in revisions %}
                    {% if revision.version == 'latest' %}
                        {% set url = url_for('wiki/index', page_path=page_path) %}
                    {% else %}
                        {% set url = url_for('wiki/index', page_path=page_path, version=revision.version) %}
                    {% endif %}
                    <tr class="{{ row_class.next() }}">
                        <td class="version-selector"><input type="radio" name="version1" value="{{ revision.version }}"{% if loop.index == 1 %} checked="checked"{% endif %}></td>
                        <td class="version-selector"><input type="radio" name="version2" value="{{ revision.version }}"{% if loop.index == 2 %} checked="checked"{% endif %}></td>
                        <td>
                            <a href="{{ url }}"><time pubdate="pubdate" datetime="{{ format_datetime(revision.updated, 'iso') }}">{{ format_datetime(revision.updated, 'medium') }}</time></a>
                            - <a href="{{ url_for('users/profile', username=revision.editor.username) }}">{{ revision.editor.username }}</a>
                            {% if revision.notes -%}
                                <span class="revision-note">({{ revision.notes }})</span>
                            {% endif %}
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
                {% if not is_first_page or next_page %}
                <tfoot>
                    <tr>
                        <td colspan="3">
                            {% if not is_first_page %}
                                &larr; <a href="javascript:history.back();">{{ _('previous page') }}</a>
                            {% endif %}
                            {% if not is_first_page and next_page %} | {% endif %}
                            {% if next_page %}
                                <a href="{{ url_for('wiki/changes', page_path=page_path, start=next_page) }}">{{ _('next page') }}</a> &rarr;
                            {% endif %}
                        </td>
                    </tr>
                </foot>
                {% endif %}
            </table>
            {% if revisions|count > 1 %}
            <fieldset class="submit">
                <input type="submit" class="button" name="submit" value="{{ _('Compare selected versions') }}">
            </fieldset>
            {% endif %}
        </form>
    {% else %}
        <p>{{ _('Weird, no changes were found.') }}</p>
    {% endif %}
{% endblock %}
